
// 本文件纯测试，可删除

// 导入
import myFns from "../../utils/myFns"

// Vuex对象
const test = {
    state() {
        return {
            testName: 'testStore.name',
            todos: [
                { id: 0, text: '写Bug', done: true },
                { id: 1, text: '吃饭', done: true },
                { id: 2, text: '睡觉', done: false }
            ]
        }
    },
    getters: {
        // 已完成任务的列表
        doneTodos: state => {
            return state.todos.filter(todo => todo.done)
        },

        // 已完成任务的数量
        doneTodosCount: (state, getters) => {
            return getters.doneTodos.length
        },

        // 通过id搜索任务
        // store.getters.getTodoById(2) // -> { id: 2, text: '...', done: false }
        getTodoById: (state) => (id) => {
            return state.todos.find(todo => todo.id === id)
        },

        // 别名
        // 在vue中把 `this.vueGetterB` 映射为 `this.$store.getters.getterNameA`
        // (调用时...mapGetters({ vueGetterB: 'getterNameA' }))
        getterNameA: state => {
            return state.todos.length
        }
    },
    mutations: {
        updateTestNameMutations (state, val) {
            state.testName = val
        }
    },
    actions: {
        updateTestNameActions ({ commit, state }, val) {
            commit('updateTestNameMutations', val)
        },
        getTestNameActions ({ commit, state }) {
            return state.testName
        },

        // 异步
        async yibu ({ commit, state }, nowTime) {
            myFns.clog('Store > test > actions > yibu > 开始', nowTime)

            return new Promise((resolve, reject)=>{
                setTimeout(()=>{
                    let bObj = new Date(nowTime)
                    let aObj = new Date()
                    let t = {
                        b: myFns.get_date_formatted('H:m:s', nowTime),
                        a: myFns.get_date_formatted('H:m:s'),
                    }
                    // 前23:28:58 后23:29:1
                    resolve('前'+ t.b +' 后' + t.a)
                }, 3000)
            })


            return state.testName
        },
    }
}


export default test